<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.global.js"></script>
</head>
<body>
    <div id="app"></div>
    <script>
        const Son = {
            props:["count"],
            template:`
            <h3>劳资是儿子：{{count}}</h3>
            `,
            /* 创建实例阶段 */
            beforeCreate(){
                console.log("beforeCreate");
            },
            created(){
                console.log("created");
            },
            
            /* 挂载阶段 */
            beforeMount(){
                console.log("beforeMount");
            },
            mounted(){
                console.log("mounted");
            },

            /* 更新阶段 */
            beforeUpdate(){
                console.log("beforeUpdate");
            },
            updated(){
                console.log("updated");
            },

            /* 卸载阶段（Vue2时代beforeDestroy+destroyed） */
            beforeUnmount(){
                console.log("beforeUnmount");
            },
            unmounted(){
                console.log("unmounted");
            },
        }
        Vue.createApp({
            data(){
                return {
                    count:0,
                    showSon:true
                }
            },
            template:`
            <son v-if="showSon" v-bind:count="count"/>
            <hr/>
            <button v-on:click="addCount">add</button>
            <button v-on:click="switchShowSon">显隐子组件</button>
            `,
            components:{
                Son
            },
            methods:{
                addCount(){
                    this.count++
                },
                switchShowSon(){
                    this.showSon = !this.showSon
                }
            }
        }).mount("#app")
    </script>
</body>
</html>